package com.wsc.wscbirthdaykeeper.managers;

import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import com.wsc.wscbirthdaykeeper.R;
import com.wsc.wscbirthdaykeeper.app.KApplication;

public class PreferenceManager extends BaseManager {
	private static String KEY_NEED_LOGIN = "KEY_NEED_LOGIN";
	private static String KEY_PASSWORD = "KEY_PASSWORD";
	private static String KEY_DEF_LOCATION = "KEY_DEF_LOCATION";

	private SharedPreferences preferences;
	private Editor editor;
	private static PreferenceManager instance;

	public static PreferenceManager getInstance() {
		if (instance == null) {
			instance = new PreferenceManager();
		}
		return instance;
	}

	@Override
	public void onCreationComplete() {
		preferences = KApplication.getContext().getSharedPreferences(ResourceManager.getStringValue(R.string.app_name), KApplication.MODE_PRIVATE);
		editor = preferences.edit();
	}

	public boolean getNeedLogin() {
		return preferences.getBoolean(KEY_NEED_LOGIN, true);
	}

	public void setNeedLogin(Boolean needLogin) {
		editor.putBoolean(KEY_NEED_LOGIN, needLogin);
		editor.commit();
	}

	public String getPassword() {
		return preferences.getString(KEY_PASSWORD, "");
	}

	public void setPassword(String password) {
		editor.putString(KEY_PASSWORD, password);
		editor.commit();
	}

	public String getLocation() {
		return preferences.getString(KEY_DEF_LOCATION, ResourceManager.getStringValue(R.string.def_location));
	}

	public void setLocation(String location) {
		editor.putString(KEY_DEF_LOCATION, location);
		editor.commit();
	}

	@Override
	public void onRefresh() {
	}

	@Override
	public void onDestroy() {
	}
}
